package com.findyou.service.impl;

import com.findyou.mapper.CategoryMapper;
import com.findyou.pojo.Article;
import com.findyou.pojo.Category;
import com.findyou.pojo.Result;
import com.findyou.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @Title: CategoryImpl
 * @Author 贾金博
 * @Package com.findyou.service.impl
 * @Date 2024/3/9 17:18
 * @description:
 */
@Service
public class CategoryImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Result add(int id, Category category) {

        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        category.setCreateUser(id);

        categoryMapper.insert(category);
        return Result.success();
    }

    @Override
    public Result ArticleCategory(int id) {
        List<Category> list = categoryMapper.findAllCategory(id);
        return Result.success(list);
    }

    @Override
    public Result update(Category category) {
        categoryMapper.update(category);
        return Result.success();
    }

    @Override
    public Result detail(int id) {
        Category category = categoryMapper.detail(id);
        return Result.success(category);
    }

    @Override
    public Result delete(int id) {
        categoryMapper.delete(id);
        return Result.success();
    }
}
